<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/metaHead.jsp"%>
<div class="column full"><div class="box"><h2 class="box-header">角色信息 </h2><div class="box-content">
		<form:form action="${mvcpath}/save.do" modelAttribute="entity" method="post">
		
		<form:hidden path="id" />
		 <label class="form-label">角色名称</label> 
		<form:input path="rolename" title="角色名称" cssClass="form-field half" />
  <p class="formfieldP"  style="width:800px;" ><label class="form-label">权限</label>
        	 <input  type="hidden" name="authIds"  id="authIds" value="${authIds}"/>
        	 <textarea onfocus="initTree();" rows="10" cols="160"  name="authNames" id="authNames" class="form-field" >${authName }</textarea>

        </p>
		<div class="clear"></div>
		<hr/>
		<div style="clear:both;height:36px;" >
		<ul style="float:right;">
		 <li style="float:left;"><input id="cancel" class="button themed" type="button" value="取 消" name="cancel" /></li>
		 <li style="float:left;"><input id="validate" class="button themed" type="submit" value="保 存" name="submit" /></li>
 		</ul>
		</div>
</form:form>
</div></div></div>
  <div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	<ul id="orgTree" class="ztree" style="margin-top:0; width:160px;"></ul>
</div>
 <link rel="stylesheet" href="${base }/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
<script type="text/javascript" src="${base }/js/tree/jquery.ztree.core-3.0.js"></script>
<script type="text/javascript" src="${base }/js/tree/jquery.ztree.excheck-3.0.js"></script>
<script type="text/javascript">
var orgTree;
var nameObject=$("#authNames");
var idObject=$("#authIds");
$(document).ready(function() {
	 var setting = {
			 	view: {selectedMulti: true},
				check: {enable: true},	
				data: {simpleData: {enable: true}} ,
				async: {enable: true,url: "${base}/core/authority/tree.do"},
				callback: {//beforeClick:beforeClick,
					onClick: cickFunction,onCheck:cickFunction}
			              };
	 var zNodes ="";
			orgTree=	$.fn.zTree.init($("#orgTree"), setting, zNodes);
});

function cickFunction(e, treeId, treeNode) {
	var	nodes=orgTree.getCheckedNodes(true);
  var 	values = "", ids="";
	for (var i=0, l=nodes.length; i<l; i++) {
	  if(!nodes[i].isParent) {
		values += nodes[i].name + ",";
		ids+= nodes[i].id + ",";
		 	 }
	}
	if (values.length > 0 ) values = values.substring(0, values.length-1);
	if (ids.length > 0 ) ids = ids.substring(0, ids.length-1);
	nameObject.attr("value", values);
	idObject.attr("value", ids);
}
function onBodyDown(event) {
	if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
		$("#menuContent").fadeOut("fast");
		$("body").unbind("mousedown", onBodyDown);
	}
}
 function showTree(){
		var nameOffset = nameObject.offset();
		$("#menuContent").css({left:nameOffset.left + "px", top:nameOffset.top + nameObject.outerHeight() + "px"}).slideDown("fast");
		$("body").bind("mousedown", onBodyDown);
}
</script>
<script type="text/javascript">
function initTree()
{
	showTree();
	var node;
	<c:forEach var="item" items="${entity.rolesAuthority}" varStatus="status">
	node=orgTree.getNodeByParam("id","${item.authority.id}",null);
	orgTree.checkNode(node,true,true);
	</c:forEach>
}
</script>
	 
 <%@ include file="/common/foot.jsp"%>
 
  